package edu.ccut.saturn.basecomponent.database.preparedstatement.impl;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import edu.ccut.saturn.basecomponent.database.preparedstatement.IPreparedStatementSet;

public class PreparedStatementSetBinaryStream implements IPreparedStatementSet {

	public void setValue(PreparedStatement statement, int i, Object value)
			throws SQLException {
		
		ByteArrayInputStream is = null;

		try {
			byte[] valueToBytes = (byte[]) value;

			is = new ByteArrayInputStream(valueToBytes);

			int length = valueToBytes.length;

			statement.setBinaryStream(i, is, length);

		} catch (RuntimeException e) {
			e.printStackTrace();
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
